#coding: utf-8
class CulturalHeritage::Model3D < ActiveRecord::Base
  validates :title, :presence => {:message => "El Titulo es requerido"}
  validates :model_url, :presence => {:message => "El id del video es requerido"}
  belongs_to :obj_user, :class_name => 'User',  :foreign_key => 'user'
  default_scope where("deleted = 0")
  validates_format_of :model_url, :with => URI::regexp(%w(http https))
  
  def display_name
    if !user.blank?
      return ''+title+' ('+obj_user.str_complete_name+')'
    else
      return ''+title+''
    end
  end

  def self.count_cultural_heritage_dependencies(id)
      return find(:all,:conditions=>["cultural_heritage_model3_ds.cultural_heritage = ? and (cultural_heritage_model3_ds.deleted = ?) ",id,0],:select=>"count(*) as 'model3_ds'")[0].model3_ds.to_i
  end

  def self.count_user_dependencies(id)
      return find(:all,:conditions=>["cultural_heritage_model3_ds.user = ? and (cultural_heritage_model3_ds.deleted = ?) ",id,0],:select=>"count(*) as 'model3_ds'")[0].model3_ds.to_i
  end
  
end
